package ysq.xyg.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.web.model.po.WebArticle;
import ysq.xyg.web.model.po.WebConfig;
import ysq.xyg.web.model.vo.WebArticleVo;
import ysq.xyg.web.model.vo.WebConfigVo;
import ysq.xyg.web.service.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 网站phone端
 *
 * @author yu sheng qiang
 * @create 2017-03-22 11:57
 **/
@RestController
public class PhoneController {
    private static Logger log= LoggerFactory.getLogger(PhoneController.class);
    @Resource
    private WebProductService webProductService;
    @Resource
    private WebTagTypeService webTagTypeService;
    @Resource
    private WebColumnTypeService webColumnTypeService;
    @Resource
    private WebBannerService webBannerService;
    @Resource
    private WebConfigService webConfigService;
    @Resource
    private WebArticleService webArticleService;

    /**
     * 统一根据栏目获取文档
     *
     * @param colId 栏目id
     * @author shengQiang yu
     * @date 2019-4-25 16:53:29
     */
    @RequestMapping(value = "/web/phone/articleList",method = RequestMethod.POST)
    public ReturnEntity acceptArticle(String colId,String cityId, @RequestParam(defaultValue="-1") int num){
        List<WebArticle> webArticleList=webArticleService.acceptList(new WebArticleVo(colId, BaseConstant.base_show_type_zs,"",cityId));
        List<WebArticle> webArticleResultList=new ArrayList<WebArticle>();
        if(num<0){
            return new ReturnEntity(webArticleList);
        }else{
            if(webArticleList!=null&&webArticleList.size()>0){
                int i=0;
                for(WebArticle webArticle:webArticleList){
                    if(i<num){
                        webArticleResultList.add(webArticle);
                    }else{
                        break;
                    }
                    i++;
                }
            }
            return new ReturnEntity(webArticleResultList);
        }

    }


    public WebConfig acceptWebConfig(){
        List<WebConfig> list=webConfigService.acceptList(new WebConfigVo());
        if(list!=null&&list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
}
